'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller } = app;
  const userExist = app.middleware.userExist();
  router.prefix('/v1');
  router.post('/user/register', controller.v1.users.register);
  router.post('/user/login', controller.v1.users.login);
  router.post('/user/detail', userExist, controller.v1.users.detail);
  router.post('/user/logout', controller.v1.users.logout);
  router.put('/user/edit', userExist, controller.v1.users.edit);
  router.get('/citys', controller.v1.commons.citys);
  router.get('/house/hot', controller.v1.houses.hots);
  router.get('/house/search', userExist, controller.v1.houses.search);
  router.get('/house/:id', userExist, controller.v1.houses.detail);
  router.post(
    '/house/:houseId/comments/add',
    userExist,
    controller.v1.comments.add
  );
  router.get(
    '/house/:houseId/comments',
    userExist,
    controller.v1.comments.lists
  );
  router.post('/order/:id/add', userExist, controller.v1.orders.add);
  router.post('/order/:id/pay', userExist, controller.v1.orders.pay);
  router.delete('/order/:id/del', userExist, controller.v1.orders.delete);
  router.get('/orders', userExist, controller.v1.orders.lists);
  router.get('/order/:id', userExist, controller.v1.orders.detail);
  router.put('/order/:id', userExist, controller.v1.orders.pay);
};
